package com.googlecode.mailnet.emf.netmodel.ui;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

import com.googlecode.mailnet.emf.netmodel.simulation.SimulationContext;

public class SimulationJob extends Job {

	SimulationContext context;
	
	public SimulationJob(SimulationContext context) {
		super("Simulation");
		this.context = context;
	}
	
	@Override
	protected IStatus run(IProgressMonitor monitor) {
		try {
			monitor.beginTask("Mailnet: network simulation", 100);
			int step = 1;
			while (!monitor.isCanceled()) {			
				context.next();
				Thread.sleep(200);
				monitor.worked(step);
			}
		} catch (Exception e) {
			System.out.println(e);
			return Status.CANCEL_STATUS;
		} finally {
			monitor.done();
		}
		return Status.OK_STATUS;
	}

}
